//
//  SearchView.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/16.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

class SearchView: UIView {
    @IBOutlet weak var button_cancel: UIButton!
   
    @IBOutlet weak var textField_search: UITextField!
    @IBAction func clickCancel(sender: AnyObject) {
        
      self.textFieldContraint.constant = 0
        
        UIView.animateWithDuration(0.5) { 
            self.layoutIfNeeded()
        }
        
        self.textField_search.resignFirstResponder()
        
    }
    @IBAction func beginEdit(sender: AnyObject) {
        
        self.textFieldContraint.constant = self.button_cancel.frame.width + 8
        UIView.animateWithDuration(0.5) {
            self.layoutIfNeeded()
        }
        
    }
    @IBOutlet weak var textFieldContraint: NSLayoutConstraint!
//    class func searchView() -> SearchView {
//        return NSBundle.mainBundle().loadNibNamed("SearchView", owner: nil, options: nil).last! as! SearchView
//    }
    
    
    override func awakeFromNib() {
        
        leftView.frame.size = CGSize(width: self.frame.height, height: self.frame.height)
        textField_search.leftView = leftView
        textField_search.leftViewMode = .Always
    }
    
    class func searchView() -> SearchView {
        return NSBundle.mainBundle().loadNibNamed("SearchView", owner: nil, options: nil).last! as! SearchView
    }
    
    
    private lazy var leftView: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        // 设置内容模式
        imageView.contentMode = .Center
        return imageView
    }()


    
    
}
